﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using DacSanMienTayOBJ;

public partial class Proccess_ProccessLockAndUnlockArticle : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LockUnlockArticle();
    }

    private void LockUnlockArticle()
    {
        try
        {
            //int modId = (int)Session["ModId"];
            int articleID = int.Parse(Request["articleID"]);
            string type = Request["type"];
            int vt = int.Parse(Request["vt"]);
            StringBuilder builder = new StringBuilder();
            if (type == "lock")
            {
                bool rs = ArticleBusiness.UpdateArticleVisible(articleID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    Article art = ArticleBusiness.GetArticleDetail(articleID, ConnectionType.AdminConnection);
                    string title = art.Title;
                    string imagePath = Utility.modHost + "/" + art.ImageArticle;

                   

                    string statusAdv = "Đang bị khóa";
                    string description = art.ContentArticle;
                    if (description != "")
                    {
                        description = HttpUtility.HtmlEncode(description);
                    }
                    string summary = art.Summary;
                    string metakey = art.Metakeyword;
                    string linkArticle = Utility.userHost + "/bai-viet/" + art.ArticleID + "-" + Utility.sefWord(art.Title) + ".html";

                    builder.Append("<td><a href=\"" + linkArticle + "\" style=\"text-decoration:none\" target=\"_blank\" >" + title + "</a></td>");

                    builder.Append("<td><a href=\"" + linkArticle + "\" style=\"text-decoration:none\" target=\"_blank\" ><image src=\"" + imagePath + "\" height=\"100px\" width=\"100px\" /></a></td>");
                    builder.Append("<td>" + art.CreateDate.ToShortDateString() + "</td>");
                    builder.Append("<td>" + statusAdv + "</td>");

                    builder.Append("<td><a href=\"#\" style=\"color:Blue; cursor:pointer\" rel=\"" + description + "\" rev=\"" + summary + "\" lang=\"" + metakey + "\" title=\"" + title + "\"  onclick=\"ShowInfoArticle('" + art.ArticleID + "','" + art.ImageArticle + "',this.title,this.rel,this.rev,this.lang)\"> Chỉnh sữa</a></td>");
                    builder.Append("<td> <input type=\"button\" title=\"" + art.ArticleID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockArticle(this.title,'unlock','" + vt + "')\" /></td>");
                    builder.Append("<td>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + art.ArticleID + "','movetop')\">Top</span><br/>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + art.ArticleID + "','movebottom')\">bottom</span>");
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("lockfaile");
                }
            }
            else if (type == "unlock")
            {
                bool rs = ArticleBusiness.UpdateArticleVisible(articleID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    Article art = ArticleBusiness.GetArticleDetail(articleID, ConnectionType.AdminConnection);
                    string title = art.Title;
                    string imagePath = Utility.modHost + "/" + art.ImageArticle;
                
                   

                    string statusAdv = "Đang active";
                    string description = art.ContentArticle;
                    if (description != "")
                    {
                        description = HttpUtility.HtmlEncode(description);
                    }
                    string summary = art.Summary;
                    string metakey = art.Metakeyword;
                    string linkArticle = Utility.userHost + "/bai-viet/" + art.ArticleID + "-" + Utility.sefWord(art.Title) + ".html";

                    builder.Append("<td><a href=\"" + linkArticle + "\" style=\"text-decoration:none\" target=\"_blank\" >" + title + "</a></td>");

                    builder.Append("<td><a href=\"" + linkArticle + "\" style=\"text-decoration:none\" target=\"_blank\" ><image src=\"" + imagePath + "\" height=\"100px\" width=\"100px\" /></a></td>");
                    builder.Append("<td>" + art.CreateDate.ToShortDateString() + "</td>");
                  
                    builder.Append("<td>" + statusAdv + "</td>");

                    builder.Append("<td><a href=\"#\" style=\"color:Blue; cursor:pointer\" rel=\"" + description + "\" rev=\"" + summary + "\" lang=\"" + metakey + "\" title=\"" + title + "\"  onclick=\"ShowInfoArticle('" + art.ArticleID + "','" + art.ImageArticle + "',this.title,this.rel,this.rev,this.lang)\"> Chỉnh sữa</a></td>");
                    builder.Append("<td> <input type=\"button\" title=\"" + art.ArticleID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockArticle(this.title,'lock','" + vt + "')\" /></td>");
                    builder.Append("<td>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + art.ArticleID + "','movetop')\">Top</span><br/>");
                    builder.Append("<span style=\"cursor:pointer; color:blue\" onclick=\"MoveArticle('" + art.ArticleID + "','movebottom')\">bottom</span>");
                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("unlockfaile");
                }
            }
            Response.End();
        }
        catch
        {

        }
    }
}